/*************************************************************************
	> File Name: P1803.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-01-23 14:19:54
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

#define MAX_N 1000000

struct Node {
    int x, y;
} arr[MAX_N + 5];

bool cmp(Node &a, Node &b) {
    return a.y < b.y;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &arr[i].x, &arr[i].y);
    }
    sort(arr, arr + n, cmp);
    int end_t = arr[0].y, cnt = 1;
    for (int i = 1; i < n; i++) {
        if (arr[i].x >= end_t) {
            cnt++;
            end_t = arr[i].y;
        }
    }
    cout << cnt << endl;
    return 0;
}
